<?php
Database($_SESSION['cid']);
class HomePageAction extends Action{
/*
首页 用于统计数量
*/
public function index(){
	//下载安装数
	$sql_IOS='select count(*) as iosnum from uri where mobiletype=\'IOS\';';
	$sql_ANDROID='select count(*) as androidnum from uri where mobiletype=\'ANDROID\';';
	$count_IOS=M('uri','','DB_MEETING')->query($sql_IOS);
	$count_ANDROID=M('uri','','DB_MEETING')->query($sql_ANDROID);
	//留言总数
	$count_comment=M('comment','','DB_MEETING')->count();
	/*//点赞量 
	$sql_vote='select  SUM(votes) as votenum from agenda_cn';
	$count_vote=M('agenda_cn','','DB_MEETING')->query($sql_vote);*/
	//在线投票结果
	$count_question=M('question','','DB_MEETING')->count();
	//总用户数量
	$rs['count_audience']=M('audience','','DB_MEETING')->where('time_insert>time_delete')->count();
	//$rs['audience_update']=$this->get_useruptTab();
	$rs['votenum']=(int)$count_vote[0]['votenum'];
	$rs['max_comment']=(int)$count_comment;
	$rs['count_IOS']=(int)$count_IOS[0]['iosnum'];
	$rs['count_ANDROID']=(int)$count_ANDROID[0]['androidnum'];
	$rs['total_count']=(int)$count_IOS[0]['iosnum']+$count_ANDROID[0]['androidnum'];
	$rs['count_question']=$count_question;
	$rs['count_speaker']=(int)M('speaker_cn','','DB_MEETING')->where('time_insert>time_delete')->count();
	$this->assign('rs',$rs);
	$this->display();
}
	
public function get_useruptTab(){
	$pagesize=10;
	$totalRow=M('audience_update','','DB_MEETING')->where('time_insert>time_delete')->count($sql_s);
	$totalpage=ceil($totalRow/$pagesize);
	$currentpage=$_POST['page'];
	$firstpage=($currentpage-1)*$pagesize;
	$sql="select nickname,time_update from audience order by time_update desc limit ".$firstpage.",".$pagesize;
	$rs=M('audience_update','','DB_MEETING')->query($sql);
	$htm='';
	if(is_array($rs) && count($rs)>0){
		$htm.='<tr>
					<th width="50%" style="text-align:center">昵称</th>
					<th width="50%" style="text-align:center">修改时间</th>
				</tr>';
		foreach($rs as $val)
		{
			$htm.='<tr>
						<td>'.$val['nickname'].'</td>
						<td>'.date('Y-m-d H:i',$val['time_update']).'</td>	
				   </tr>';	
		}
		$htm.='<tr><td colspan="2" align="center">';
			if($currentpage>1)
			{
				$htm.='<a href="javascript:void(0)" page="1">首页</a> <a href="javascript:void(0)" page="'.($currentpage-1).'">上一页</a> ';
			}
			for($i=1;$i<=$totalpage;$i++)
			{
				$htm.='<a href="javascript:void(0)" page="'.$i.'">'.$i.'</a> ';
			}
			if($currentpage<$totalpage)
			{
				$htm.='<a href="javascript:void(0)" page="'.($currentpage+1).'">下一页</a> <a href="javascript:void(0)" page="'.$totalpage.'">尾页</a>';
			}
		$htm.='</td></tr>';	
	}
	else
	{
		$htm.='<tr><td colspan="2" align="center">暂无数据</td></tr>';	
	}
	echo $htm;
}

/*
通讯录EXCEL表导出
*/
public function audience_excel(){
	$file_type = "vnd.ms-excel";  // excel表头固定写法
	$file_ending = "xls"; // excel表的后缀名
	header("Content-Type: application/$file_type"); 
	header("Content-Disposition: attachment; filename=audience".time().".$file_ending"); // agentfile导出的表名
	header("Pragma: no-cache"); // 缓存
	header("Expires: 0");
	$sql_audience='SELECT * FROM audience';
	$arr_s=M('audience','','DB_MEETING')->query($sql_audience);
?>
<html xmlns:o='urn:schemas-microsoft-com:office:office' 
xmlns:x='urn:schemas-microsoft-com:office:excel'  
xmlns='http://www.w3.org/TR/REC-html40'>  
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  
<html>  
    <head>  
        <meta http-equiv='Content-type' content='text/html;charset=utf-8'/>  
        <style id='Classeur1_16681_Styles'></style>  
    </head>  
    <body>  
        <div id='Classeur1_16681' align=center x:publishsource='Excel'>
        <table border="1" cellpadding="0" cellspacing="0">
        	<tr>
                <th>编号</th>
                <th>用户名</th>
                <th>密码</th>
                <th>姓名</th>
                <th>电话</th>
                <th>邮箱</th>
                <th>职位</th>
              <!--   <th>头像</th> -->
                <th>使用状态</th>
            </tr>
<?php
	foreach($arr_s as $val){ 
?>
			<tr>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_id']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_username']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_pwd']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_name']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_tel']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_email']?></td>
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_position']?></td>
                <!-- <td style="font-size:16px; text-align:center"><?php echo C('DOMAIN_NAME').__ROOT__.'/'.$val['audience_portrait']?></td> -->
                <td style="font-size:16px; text-align:center"><?php echo $val['audience_state']=$val['audience_state']==1?'正常':'停用' ?></td>
            </tr>
<?php 
    }
	echo " </table></div></body></html> ";
}


/*请假EXCEL表导出*/
public function Leave_excel(){
	$file_type = "vnd.ms-excel";  // excel表头固定写法
	$file_ending = "xls"; // excel表的后缀名
	header("Content-Type: application/$file_type"); 
	header("Content-Disposition: attachment; filename=leave".time().".$file_ending"); // agentfile导出的表名
	header("Pragma: no-cache"); // 缓存
	header("Expires: 0");
	//$sql_leave="SELECT 'leave.leave_id, leave.leave_uid, leave.leave_startTime, leave.leave_endTime, leave.leave_type, leave.leave_reason, leave.leave_state, leave_type.type_name, leave_type.type_prove, leave_prove.prove_image_path, audience.audience_name' FROM  'leave' LEFT JOIN leave_type ON 'leave.leave_type' = 'leave_type.type_id' LEFT JOIN leave_prove ON 'leave.leave_id' = 'leave_prove.leave_id' LEFT JOIN audience ON 'leave.leave_uid' = 'audience.audience_id' ORDER BY 'leave.leave_id' DESC ";
	$arr_s=M('leave','','DB_MEETING')->join('leave_type on leave.leave_type = leave_type.type_id')->join('leave_prove on leave.leave_id = leave_prove.leave_id')->join('audience on leave.leave_uid = audience.audience_id')->field('leave.leave_id,leave.leave_uid,leave.leave_startTime,leave.leave_endTime,leave.leave_type,leave.leave_reason,leave.leave_state,leave_type.type_name,leave_type.type_prove,leave_prove.prove_image_path,audience.audience_name')->order('leave.leave_id desc')->select();
?>
<html xmlns:o='urn:schemas-microsoft-com:office:office' 
xmlns:x='urn:schemas-microsoft-com:office:excel'  
xmlns='http://www.w3.org/TR/REC-html40'>  
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  
<html>  
    <head>  
        <meta http-equiv='Content-type' content='text/html;charset=utf-8'/>  
        <style id='Classeur1_16681_Styles'></style>  
    </head>  
    <body>  
        <div id='Classeur1_16681' align=center x:publishsource='Excel'>
        <table border="1" cellpadding="0" cellspacing="0">
        	<tr>
                <th>编号</th>						
                <th>请假类型</th>
                <th>请假人</th>
                <th>请假理由</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>请假天数</th>
                <th>审批状态</th>
              <!--   <th>头像</th> -->
                
            </tr>
<?php
	foreach($arr_s as $val){ 
?>
	<tr>
           <td style="font-size:16px; text-align:center"><?php echo $val['leave_id']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['type_name']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['audience_name']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['leave_reason']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['leave_startTime']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['leave_endTime']?></td>

           <td style="font-size:16px; text-align:center">
	           <?php  
	           		if(($val['leave_endTime']-$val['leave_startTime'])%(24*3600)==0){
	           			echo ($val['leave_endTime']-$val['leave_startTime'])/(24*3600)."天";
	           		}else{
	           			echo floor(($val['leave_endTime']-$val['leave_startTime'])/(24*3600))."天/".floor((($val['leave_endTime']-$val['leave_startTime'])%(24*3600))/3600)."小时";
	           		}
	           	?>
           	</td>
           <td style="font-size:16px; text-align:center">
           		<?php 
	           		switch($val['leave_state']){
	           			case 0:
	           				echo "审批中";
	           			break;
	           			case 1:
	           				echo "已审批";
	           			break;
	           			case 2:
	           				echo "已驳回";
	           			break;
	           			case 3:
	           				echo "申请销假";
	           			break;
	           			case 4:
	           				echo "同意销假";
	           			break;
	           			case 5:
	           				echo "驳回销假";
	           			break;
	           		}
           		?>
           	</td>                
                
      </tr>
<?php 
    }
	echo " </table></div></body></html> ";
}

//事务跟踪excel表格下载
public function Event_excel(){
	$file_type = "vnd.ms-excel";  // excel表头固定写法
	$file_ending = "xls"; // excel表的后缀名
	header("Content-Type: application/$file_type"); 
	header("Content-Disposition: attachment; filename=event".time().".$file_ending"); // agentfile导出的表名
	header("Pragma: no-cache"); // 缓存
	header("Expires: 0");
	$sql = "select * from event";	
	$arr_s=M('event','','DB_MEETING')->query($sql);
?>
<html xmlns:o='urn:schemas-microsoft-com:office:office' 
xmlns:x='urn:schemas-microsoft-com:office:excel'  
xmlns='http://www.w3.org/TR/REC-html40'>  
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  
<html>  
    <head>  
        <meta http-equiv='Content-type' content='text/html;charset=utf-8'/>  
        <style id='Classeur1_16681_Styles'></style>  
    </head>  
    <body>  
        <div id='Classeur1_16681' align=center x:publishsource='Excel'>
        <table border="1" cellpadding="0" cellspacing="0">
        	<tr>
                <th>编号</td>
                <th>事件名称</td>
                <th>发起人</td>
                <th>开始时间</td>
                <th>结束时间</td>
                <th>项目名称</td>
				<th>事务状态</td>
				<th>状态时间</th>
            </tr>
<?php
	foreach($arr_s as $val){ 
?>
	<tr>
           <td style="font-size:16px; text-align:center"><?php echo $val['event_id']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['event_name']?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['event_launch_name']?></td>
           <td style="font-size:16px; text-align:center"><?php echo date("Y-m-d H:i:s",$val['event_startTime']) ?></td>
           <td style="font-size:16px; text-align:center"><?php echo date("Y-m-d H:i:s",$val['event_endTime']) ?></td>
           <td style="font-size:16px; text-align:center"><?php echo $val['project_name']?></td>

           <td style="font-size:16px; text-align:center">
		   <?php
				switch($val['event_state']){
					case 6:
						echo "已发起";
					break;
					case 1:
						echo "已审核";
					break;
					case 2:
						echo "已提交";
					break;
					case 3:
						echo "已执行";
					break;
					case 4:
						echo "已验收";
					break;
					case 5:
						echo "已归档";
					break;
				}
		   ?>
		   </td>
           <td style="font-size:16px; text-align:center"><?php echo date("Y-m-d H:i:s",$val['time_update']) ?></td>
      </tr>
<?php 
    }
	echo " </table></div></body></html> ";
}








}


?>